package com.cp_smss.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cp_smss.model.Department;
import com.cp_smss.model.Project;
import com.cp_smss.model.User;
import com.cp_smss.service.BusinessService;
import com.cp_smss.service.DepartmentService;
import com.cp_smss.service.UserService;

/**
 * 异步请求controller
 * @author Administrator
 *
 */
@Controller
public class DialogController {
	
	@Autowired
	private DepartmentService departmentService;
	@Autowired
	private BusinessService businessService;
	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/newProject")
	public String newProject(){
		return "dialog/newProject";
	}
	
	@RequestMapping(value="/editProject")
	public String editProject(Project project,ModelMap modelMap){
		project = businessService.getProjectByCondition(project);
		modelMap.put("project", project);
		return "dialog/editProject";
	}
	
	@RequestMapping(value="/newUser")
	public String newUser(ModelMap modelMap) throws BindException{
//		if(!Authorizer.authorize(request, GlobalConstants.ROLE_ADMIN)){
//			return "";
//		}
		List<Department> departments = departmentService.getDepartments();
		modelMap.put("departments", departments);
		return "dialog/newUser";
	}
	
	@RequestMapping(value="editUser")
	public String editUser(User user,ModelMap modelMap){
		List<Department> departments = departmentService.getDepartments();
		modelMap.put("departments", departments);
		user = userService.getUserByCondition(user);
		modelMap.put("user", user);
		return "dialog/editUser";
	}
}
